// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui';
import { Checkbox } from 'ant-design-vue';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App'
import router from './router'
import VueAMap from 'vue-amap'
import http from './api/http'
import Moment from "moment"
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import 'lib-flexible'
import './utils/Blob'
import './utils/Export2Excel'

import JsonExcel from 'vue-json-excel'

import XLSX from 'xlsx'
Vue.prototype.XLSX = XLSX
Vue.component('downloadExcel', JsonExcel)
Vue.prototype.moment = Moment
Vue.use(VueQuillEditor, /* { default global options } */)
Vue.use(VueAMap);
VueAMap.initAMapApiLoader({
  key: '09929fb9783b7e270f86b555356ebb73',
  plugin: ['AMap.PolyEditor', 'AMap.MouseTool'], //需要的高德地图插件，需要什么插件添加什么插件（这里只是其中一部分）
  // 默认高德 sdk 版本为 1.4.4
  v: '1.4.4',
  uiVersion: '1.0.11'
});
Vue.use(ElementUI);
Vue.use(Checkbox);
Vue.prototype.$http = http;
Vue.config.productionTip = false
//    //引入侧边栏组件
import layout from "./layout/layout.vue" //引入头部组件


router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {


    if (!!localStorage.getItem('userScope')) {
      document.title = to.meta.title


    } else {
      document.title = '登录'
    }
    if (to.meta.title != '登录') {
      Vue.component("lay-out", layout);
    } else {
      Vue.component("lay-out", 'undefined');
      // console.log(Vue.component("lay-out", 'undefined'))
    }
  }
  // console.log(to.meta.title)
  // 非登录页无token拦截
  const token = localStorage.getItem('key') || ''
  if (!token && to.name !== 'login') {
    next({
      path: '/login'
      // query: { redirect: to.fullPath }
    })

  } else {
    next()
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  render: h => h(App),
  components: {
    App
  },

  template: '<App/>'
})

